| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- import NextAuth from 'next-auth';
- import Credentials from 'next-auth/providers/credentials';
- import dbConnect from '../../../utils/helpers/dbHelpers';
- const User = require('../../../models/user');
-
- export default NextAuth({
- session: {
- strategy: 'jwt',
- },
- callbacks: {
- async jwt({ token, user, account, profile, isNewUser }) {
- return { ...token, ...user };
- },
- async session({ session, token, user }) {
- return session;
- },
- },
- providers: [
- Credentials({
- name: 'Credentials',
- credentials: {
- username: { label: 'Username', type: 'text' },
- password: { label: 'Password', type: 'password' },
- },
- // @ts-ignore
- async authorize(credentials) {
- if (credentials) {
- await dbConnect();
-
- const userData = await User.findByCredentials(
- credentials.username,
- credentials.password
- );
- return { user: userData };
- }
- return null;
- },
- }),
- ],
- });
|